package com.sneakxy.cloudbase.platform.repository;

import java.util.List;

import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.sneakxy.cloudbase.platform.bean.Launcher;

/**
 * 
 * @author 潜行的青衣
 * @see
 */
@Repository
public interface LauncherRepository extends BaseRepository<Launcher, String> {

	@Select({
		"select l.module from t_mb4j_launcher l",
		"left join t_mb4j_l_setting ls",
		"on l.id=ls.lid and ls.account_id=#{accountId}",
		"where (ls.enable is null or ls.enable = 1) and l.enable= 1",
		"order by l.sort"
	})
	@ResultType(String.class)
	public List<String> findAllLauncherModules(@Param("accountId") String accountId);
	
	
	@Select({
		"select l.id,l.name,l.module,l.memo,l.sort,l.createtime,l.updatetime,",
		"(case when ls.enable is null or ls.enable = 1 then 1 else 0 end) as enable",
		"from t_mb4j_launcher l",
		"left join t_mb4j_l_setting ls",
		"on l.id=ls.lid and ls.account_id=#{accountId}",
		"where l.enable= 1 and l.manual = 1",
		"order by l.sort,l.createtime"
	})
	@ResultMap("Launcher")
	public List<Launcher> findAllLaunchers(@Param("accountId") String accountId);
	
}
